package com.heima.controller.vm_service;


import com.heima.pojo.dto.NodeSaveDto;
import com.heima.pojo.entity.Node;
import com.heima.pojo.vo.NodeRegionBusinessVo;
import com.heima.pojo.vo.VmTypeNodeRegionVo;
import com.heima.pojo.vo.PageVo;
import com.heima.service.NodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/vm-service/node")
@Slf4j
public class NodeController {

    @Autowired
    private NodeService nodeService;

    /**
     * 点位搜索 分页条件查询
     */
    @GetMapping("/search")
    public PageVo<NodeRegionBusinessVo> nodePage(@RequestParam Integer pageIndex, Integer pageSize,
                                                 @RequestParam(required = false) String name,
                                                 @RequestParam(required = false) String regionId){
        PageVo<NodeRegionBusinessVo> nodePageVos=  nodeService.getNodePage(pageIndex,pageSize,name,regionId);
        return nodePageVos;
    }
    /**
     * 新增点位
     */
    @PostMapping
    public Boolean save(@RequestBody NodeSaveDto nodeSaveDto){
       return nodeService.save(nodeSaveDto);
    }
    /**
     * 修改点位
     *
     */
    @PutMapping("/{nodeId}")
    public Boolean update(@PathVariable String nodeId, @RequestBody Node node){
        log.info("----------------{}",nodeId);
        Long id = Long.valueOf(nodeId);
        return nodeService.update(id,node);
    }
    /**
     * 删除点位
     */
    @DeleteMapping("/{nodeId}")
    public Boolean delete(@PathVariable String nodeId){
        return nodeService.delete(nodeId);
    }


    /**
     * 获取类型和点位详情
     * @param nodeId
     * @return
     */
    @GetMapping("/vmList/{nodeId}")
    public List<VmTypeNodeRegionVo> getNodeDetail(@PathVariable String nodeId){
        Long id = Long.valueOf(nodeId);
        List<VmTypeNodeRegionVo> vmTypeNodeRegionVos = nodeService.getNodeDetail(id);
        return vmTypeNodeRegionVos;
    }

    /**
     * 获取点位数量
     * @return
     */
    @GetMapping("/count")
    public Integer getNodeCount(){
       Integer count = nodeService.getNodeCount();
        return count;
    }
}















